﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using GameServer.Managers;
using GameServer.Virtual_Objects.User;

namespace GameServer.Networking.Packets
{
    class PACKET_EXPIRE_ITEM : Packet
    {
        public PACKET_EXPIRE_ITEM(virtualUser User)
        {
            newPacket(30976);
            addBlock(1);
            addBlock(User.getSlots()); //Slots Enable
            // Player Equipment //
            for (int Class = 0; Class < 5; Class++)
            {
                StringBuilder ClassBuilder = new StringBuilder();

                for (int Slot = 0; Slot < 8; Slot++)
                {
                    ClassBuilder.Append(User.Equipment[Class, Slot]);
                    if (Slot != 7) ClassBuilder.Append(",");
                }
                addBlock(ClassBuilder.ToString());
            }
            // Build Inventory //
            StringBuilder Items = new StringBuilder(); int Itemcount = 0;
            for (int I = 0; I < 30; I++)
            {
                if (User.Inventory[I] != null)
                {
                    InventoryItem _Inv = User.Inventory[I];
                    TimeSpan ExpireTime = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0).AddSeconds(_Inv._StartTime);

                    Items.Append(_Inv._Code.ToUpper() + "-3-0-" + _Inv._StartTime + "-0-0-0-0-0-9999-9999,");/*+ ExpireTime.TotalSeconds +*/
                    Itemcount++;
                }
            }

            for (int I = 0; I < (30 - Itemcount); I++)
            {
                Items.Append("^,");
            }

            addBlock(Items.ToString().Remove(Items.ToString().Length - 1));
            addBlock(User.LeftItems.Count);
            foreach (string Item in User.LeftItems)
            {
                addBlock(Item);
            }
            User.LeftItems.Clear();
        }
    }
}
